const CompressionPlugin = require("compression-webpack-plugin")
const BiyiMsConfigPlugin = require("biyi-ms-config-plugin")
const indexHtml = require("./index.html")
const webpack = require('webpack')  //添加webpack
module.exports = {
  devServer: {
    port: 80, // 端口
    proxy: {
      "/": {
        target: "http://localhost:8083/api-elevator-sup",
        changeOrigin: true,
        pathRewrite: {
          "^/": ""
        }
      },
      // // 代理
      // "/buildingLogin": {
      //   target: "http://10.1.89.26:8081",
      //   changeOrigin: true,
      //   pathRewrite: {
      //     "^/buildingLogin": ""
      //   }
      // },
      // "/buildingBase": {
      //   target: "http://10.1.90.162:9006",
      //   changeOrigin: true,
      //   pathRewrite: {
      //     "^/buildingBase": ""
      //   }
      // },
    }
  },

  // publicPath: "/",
  lintOnSave:false,
  publicPath: "/sup",
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        jQuery: "jquery",
        $: "jquery"
      })
    ]
  },
  chainWebpack: config => {
    config.plugin("provide").use(webpack.ProvidePlugin, [{
      $: "jquery",
      jquery: "jquery",
      "window.jQuery": "jquery"
    }]
    )

    // 开启js、css压缩，生成gz压缩文件
    if (process.env.NODE_ENV === "production") {
      config.plugin("compressionPlugin").use(
        new CompressionPlugin({
          test: /\.js$|\.html$|\.css$|\.svg$/, // 匹配文件名
          threshold: 102400, // 对超过100k的数据压缩
          deleteOriginalAssets: false // 不删除源文件
        })
      )
      config.plugin("BiyiMsConfigPlugin").use(
        new BiyiMsConfigPlugin([
          {
            fileName: "micro-service-config.js",
            path: "public/configs",
            content: ""
          },
          {
            fileName: "index.html",
            path: "public",
            content: indexHtml
          }
        ])
      )
    }
  },
  transpileDependencies: ["biyi-admin", "biyi-captcha"],
  productionSourceMap: true, // 生产环境是否生成 sourceMap 文件
}
